﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Hangjing.Common;
using Hangjing.SQLServerDAL;
using Hangjing.Model;
using System.Text;

/// <summary>
/// 返回配送员位置(json)
/// </summary>
public partial class qy_54tss_Admin_ajax_GetDeliverModel : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string id = WebUtility.InputText(Request["id"]);
        Response.Clear();

        Deliver dal = new Deliver();

        IList<DeliverInfo> list = dal.GetListWithOrderNum(1000, 1, "Deliver.dataid="+id, "TOrderNum", 1);

        string json = "";
        foreach (DeliverInfo info in list)
        {
            json = "{\"lat\":\"" + info.Lat + "\",\"lng\":\"" + info.Lng + "\",\"d_name\":\"" + info.Name + "\",\"ordernum\":\"" + info.processcount + "\"";
            json += ",\"carstate\":\""+info.carstate+"\"";
            json += ",\"direction\":\"" + info.direction + "\"";
            json += ",\"Phone\":\"" + info.Phone + "\"";
            json += ",\"speed\":\"" + info.speed + "\"";

            //todo 查询最近接单的订单商家名称，商家地址，用户地址。
            IList<simpleorderInfo> orders = new Custorder().GetDliverList(id);
            simpleorderInfo order = orders.FirstOrDefault();
            if (order == null)
            {
                order = new simpleorderInfo();
                order.TogoAddress = "";
                order.AddressText = "";
                order.TogoName = "";
            }

            json += ",\"TogoName\":\"" + order.TogoName + "\"";
            json += ",\"TogoAddress\":\"" + order.TogoAddress + "\"";
            json += ",\"AddressText\":\"" + order.AddressText + "\",";


            json += "\"orderlist\":" + Newtonsoft.Json.JsonConvert.SerializeObject(orders) + "";



        }
        json += "}";

        Response.Write(json);

        Response.End();
    }
}
